package parsing.google;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import core.objects.BaseObject;

public class HttpConnection {

	static BaseObject doRequest(String url) {
		
		BaseObject parsedObject = null;
		HttpURLConnection conn = null;
		
		try {
			URL obj = new URL(url);
			conn = (HttpURLConnection)obj.openConnection();
			conn.setRequestMethod("GET");
			conn.setRequestProperty("User-Agent", "Chrome");
						
			BufferedReader in = new BufferedReader(
			        new InputStreamReader(conn.getInputStream()));
			String inputLine;
			StringBuffer responseBuffer = new StringBuffer();
	 
			while ((inputLine = in.readLine()) != null) {
				responseBuffer.append(inputLine);
			}
			in.close();
						
			parsedObject =  ResponseParser.parseJSONResponse(responseBuffer.toString());
		} catch (Exception e) {
			//do nothing, null will be returned
		}
		
		return parsedObject;
		
	}
	
}
